// pages/delayControll/delayControl.js
import led from '../api/led';
const speeds = [];
for (let i = 0; i <= 1000; i+=50) {
  speeds.push(i)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    speeds,
    speed:0,
    isStreamLedOn: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    led.turnOffLed();
  },
  onUnload(){
    led.streamLed(0);
  },

  streamLed(){
    this.data.isStreamLedOn = ! this.data.isStreamLedOn;
    led.streamLed(this.data.isStreamLedOn);
  },
  controlStreamLed(e){
    const index = e.detail.value[0];
    this.setData({
      speed:this.data.speeds[index]
    })
    led.controlStreamLed(this.data.speed);
  }
})